package core.genetic;

import java.util.Arrays;

import core.*;

import utility.Utils;

public class Individual
{
	private final double[] genes;

	public Individual(int length) {
		genes = new double[length];
	}
	
	public Individual(double[] genes) {
		this.genes = genes;
	}
	
	public Individual(Individual ind) {
		this.genes = ind.genes.clone();
	}
	
	public static Individual createRandom(int length) {
		Individual ind = new Individual(length);
		for(int i = 0;i<length;i++)
			ind.genes[i] = Mode.mode.singleMutation.getMutated(0);
		return ind;		
	}
	
	public int getLength(){
		return genes.length;
	}
	
	public double getGene(int i) {
		return genes[i];
	}

	public void setGene(int i, double gene) {
		this.genes[i] = gene;
	}
	
	public double[] getGenes() {
		return genes;
	}
	
	public void set(Individual ind) {
		System.arraycopy(ind.getGenes(),0,genes,0,genes.length);
	}
	
	@Override
	public String toString() {
		return Arrays.toString(genes);
	}
	
	@Override
	public boolean equals(Object obj) {
		return Arrays.equals(genes, ((Individual)obj).genes);
	}
	
}
